using System.Windows;

namespace RobotPratolSolution.Pages
{
    public partial class CronExpressionDialog : Window
    {
        public string SelectedCronExpression { get; private set; } = "0 0/5 * * * ?";

        public CronExpressionDialog()
        {
            InitializeComponent();
        }

        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            switch (PresetCombo.SelectedIndex)
            {
                case 0:
                    SelectedCronExpression = "0 * * * * ?";
                    break;
                case 1:
                    SelectedCronExpression = "0 0/5 * * * ?";
                    break;
                case 2:
                    SelectedCronExpression = "0 0 * * * ?";
                    break;
                case 3:
                    SelectedCronExpression = "0 0 0 * * ?";
                    break;
                case 4:
                    SelectedCronExpression = "0 0 3 * * ?";
                    break;
                case 5:
                    SelectedCronExpression = $"0 {MinuteBox.Text} {HourBox.Text} * * ?";
                    break;
            }
            if (PresetCombo.SelectedIndex == 4)
            {
                if (!int.TryParse(MinuteBox.Text, out int minute) || minute < 0 || minute > 59 ||
                    !int.TryParse(HourBox.Text, out int hour) || hour < 0 || hour > 23)
                {
                    MessageBox.Show("请输入有效的分钟（0-59）和小时（0-23）");
                    return;
                }
            }
            DialogResult = true;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}